<template>
  <div class="record">
    <el-table
        :data="tableData"
        style="width: 100%;height: 340px;">
      <el-table-column
          type="index"
          :index="indexMethod">
      </el-table-column>
      <el-table-column
          prop="phone"
          label="电话">
      </el-table-column>
      <el-table-column
          prop="userName"
          label="用户名">
      </el-table-column>
      <el-table-column
          prop="creatDate"
          label="申请时间">
      </el-table-column>
      <el-table-column
          prop="status"
          label="状态">
      </el-table-column>
      <el-table-column
          fixed="right"
          label="操作"
          width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">封禁/解封</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        small
        layout="prev, pager, next"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="allInfo.pageNum"
        :page-size="allInfo.pageSize"
        :total="allInfo.total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "ManageUser",
  data() {
    return {
      page: {
        pageNum: 1,
        pageSize: 5
      },
      tableData: [],
      allInfo: {},
    }
  },
  mounted() {
    this.get()
  },
  methods: {
    handleClick(row) {
      this.$confirm('此操作将【封禁/解禁】用户, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http.put("/admin/ban/" + row.id).then(res => {
          if (res.code == 200) {
            this.$message.success("操作成功")
            this.get()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    get() {
      this.$http.post("/admin/pageUser", this.page).then(async data => {
        let res = data.data.list
        res.map(i => {
          i.status = i.status == 1 ? "正常" : "封禁"
        })
        this.tableData = res
        this.allInfo = data.data
      })
    },
    getUserBasicsInfo(id) {
      return new Promise(resolve => {
        this.$http.get("/user/getUserBasicsInfo/" + id).then(data => {
          resolve(data.data)
        })
      })
    },
    // 监听页数变化
    handleSizeChange(pageSie) {
      this.page.pageSize = pageSie
      this.get()
    },
    // 监听当前页变化
    handleCurrentChange(PageNum) {
      this.page.pageNum = PageNum
      this.get()
    },
    indexMethod(index) {
      return index + 1;
    },
  }
}
</script>

<style scoped>
.record {
  width: 980px;
  float: right;
}
</style>